package cn.sylinx.horm.example.section15;

import java.io.Serializable;

import cn.sylinx.horm.core.SqlClient;
import cn.sylinx.horm.starter.CommonStarter;

public class Section15 {

    static final String CONFIG_FILE = "section15.properties";

    public static void main(String[] args) {

        CommonStarter commonStarter = new CommonStarter(CONFIG_FILE);
        commonStarter.start(); // 启动

        test();
    }

    static void test() {

        SqlClient sqlClient = SqlClient.getDefaultClient();
        MyExample15 myExample15 = new MyExample15();
        myExample15.setFieldNumber("number");
        myExample15.setFieldName("name");
        Serializable pk = sqlClient.save(myExample15);
        System.out.println("save pk -> " + pk);

        MyExample15 myExample15Update = new MyExample15();
        myExample15Update.setId(Long.parseLong(pk.toString()));
        myExample15Update.setFieldName("name_update");
        int count = sqlClient.update(myExample15Update);
        System.out.println("update count -> " + count);

        MyExample15 myExample15Query = sqlClient.get(pk, MyExample15.class);
        System.out.println("query -> " + myExample15Query);
    }
}
